// SpeedOrderDoc.h : interface of the CSpeedOrderDoc class
//
/////////////////////////////////////////////////////////////////////////////

#if !defined(AFX_SPEEDORDERDOC_H__C1AB8377_1A4E_4C71_B76C_C844F805E1C8__INCLUDED_)
#define AFX_SPEEDORDERDOC_H__C1AB8377_1A4E_4C71_B76C_C844F805E1C8__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include "ewave_lib.h"

class CSpeedOrderDoc : public CDocument
{
protected: // create from serialization only
	CSpeedOrderDoc();
	DECLARE_DYNCREATE(CSpeedOrderDoc)

// Attributes
public:

	CString       m_InstrumentName;
	PriceNodeVec  m_PriceNodesRaw;
	int           m_PriceNodeIntervalRaw;   // in seconds

	PriceNodeVec  m_PriceNodes;
	int           m_PriceNodeInterval;      // in seconds, typical values can be from 30 minutes, 60 minutes etc., then days, weeks, months
	int           m_PriceNodesPerInterval;  // only valid values: 1 or 2

	PolyWaveVec   m_MonoWaves;
	tNodeSet      m_MonoWaveNodes;

	// 
	tNodePairSet  m_SignalMatches;
	tNodePairSet  m_SignalMatches2up;
	tNodePairSet  m_SignalMatches2down;
	tNodeSet      m_LocalExtremes;

// Operations
public:

// Overrides
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CSpeedOrderDoc)
	public:
	virtual BOOL OnNewDocument();
	virtual void Serialize(CArchive& ar);
	//}}AFX_VIRTUAL

// Implementation
public:
	virtual ~CSpeedOrderDoc();
#ifdef _DEBUG
	virtual void AssertValid() const;
	virtual void Dump(CDumpContext& dc) const;
#endif

protected:
	void ImportFile(CFile* fp);
	void ExportFile(CFile* fp, const char* isin);
	void ExportFileRaw(CFile* fp, const char* isin);
	BOOL ParseBufferTicker(char * parsebuffer, DWORD fileLength);
	BOOL WriteMonoWaves();
// Generated message map functions
protected:
	//{{AFX_MSG(CSpeedOrderDoc)
		// NOTE - the ClassWizard will add and remove member functions here.
		//    DO NOT EDIT what you see in these blocks of generated code !
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()

	// Generated OLE dispatch map functions
	//{{AFX_DISPATCH(CSpeedOrderDoc)
		// NOTE - the ClassWizard will add and remove member functions here.
		//    DO NOT EDIT what you see in these blocks of generated code !
	//}}AFX_DISPATCH
	DECLARE_DISPATCH_MAP()
	DECLARE_INTERFACE_MAP()
public:
	virtual BOOL OnOpenDocument(LPCTSTR lpszPathName);
	virtual void SetPathName(LPCTSTR lpszPathName, BOOL bAddToMRU = TRUE);
};


inline double CalcNodeSetProfit(const tNodePairSet& s, bool bPrintAll = false)
{
	double profitSum = 0.0;
	tNodePairSet::const_iterator it = s.begin();
	for (; it != s.end(); it++)
	{
		tNodePair match = (*it);
		double profit = 100.0 * (match.second->mLast - match.first->mLast) / match.first->mLast;
		if (bPrintAll)
			TRACE("%s %g\n", match.first->mDate.Format(), profit);
		profitSum += profit;
	}
	return (s.size() > 0 ? profitSum / s.size() : 0.0);
}

/////////////////////////////////////////////////////////////////////////////

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_SPEEDORDERDOC_H__C1AB8377_1A4E_4C71_B76C_C844F805E1C8__INCLUDED_)
